package com.njsf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njsf.dao.BookMapper;
import com.njsf.dto.ResponseJson;
import com.njsf.pojo.Book;
import com.njsf.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
<<<<<<< HEAD
    public PageInfo<Book> getBooks(Integer start, Integer pageSize, String bookName) {
        PageHelper.startPage(start,pageSize);
        List<Book> all = bookMapper.findAll(bookName);
=======
    public PageInfo<Book> getBooks(Integer start, Integer pageSize) {
        PageHelper.startPage(start,pageSize);
        List<Book> all = bookMapper.findAll();
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
        PageInfo<Book> pageInfo = new PageInfo<>(all);
        return pageInfo;
    }

    @Override
    public ResponseJson add(Book book) {
        ResponseJson responseJson = null;
        int flag = bookMapper.insert(book);
        if (flag == 1){
            responseJson = new ResponseJson(100,"保存成功!");
        }else{
            responseJson = new ResponseJson(101,"保存失败!");
        }
        return responseJson;
    }

    @Override
    public Book bookDetail(Integer id) {
        Book book = bookMapper.findById(id);
        return book;
    }

<<<<<<< HEAD
    @Override
    public ResponseJson alter(Book book) {
        ResponseJson responseJson = null;
        int flag = bookMapper.update(book);
        if (flag == 0){
            responseJson = new ResponseJson(101,"修改失败!");
        }else{
            responseJson = new ResponseJson(100,"修改成功!");
        }
        return responseJson;
    }

    @Override
    public ResponseJson deleteById(Integer id) {
        ResponseJson responseJson = null;
        int flag = bookMapper.deleteById(id);
        if (flag == 0){
            responseJson = new ResponseJson(101,"删除失败!");
        }else{
            responseJson = new ResponseJson(100,"删除成功!");
=======

    /*假删除，将书籍状态设置为不可用*/
    @Override
    public ResponseJson delOneBook(Integer id) {
        ResponseJson responseJson = null;
        int isDelBook = bookMapper.delBook(id);
        if (isDelBook == 1){
            responseJson = new ResponseJson(100,"删除成功!");
        }else{
            responseJson = new ResponseJson(101,"删除失败!");
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
        }
        return responseJson;
    }

    @Override
<<<<<<< HEAD
    public ResponseJson deleteList(List<Integer> ids) {
        ResponseJson responseJson = null;
        int flag = bookMapper.deleteList(ids);
        if (flag == 0){
            responseJson = new ResponseJson(101,"删除失败!");
        }else{
            responseJson = new ResponseJson(100,"删除成功!");
        }
        return responseJson;
    }

=======
    public ResponseJson updateBook(Book book) {
        ResponseJson responseJson = null;
        int flag = bookMapper.updateBook(book);
        if (flag == 1){
            responseJson = new ResponseJson(100,"修改成功!");
        }else{
            responseJson = new ResponseJson(101,"修改失败!");
        }
        return responseJson;

    }
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8

}
